package cn.z2huo.demo.kafka.spring.retry.nonblock.support;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * <p>
 *
 * <p>如果 dlt 处理方法也处理失败，有两种可用的行为
 * <ul>
 *      <li>ALWAYS_RETRY_ON_ERROR，记录被转发会 DLT 主题</li>
 *      <li>FAIL_ON_ERROR，结束执行，不转发消息</li>
 * </ul>
 *
 * <p>测试日志如下
 * 2025-05-03 01:36:48.081  INFO 58935 --- [demo-kafka-spring-producer] [kafka-producer-network-thread | demo-kafka-spring-consumer-1] c.z.d.k.s.r.s.Cluster1ProducerListener                       : kafka send Message success, topic is retry-test-topic-dlt, partition is 1, timestamp is 1746207408071, record value is {"id":54919281309270047,"userCode":"userCode RiVpyjee","userName":"userName fMVfGvwz","validDate":"2025-05-03","invalidDate":"2026-05-03","validFlag":"1","deleteFlag":"0","createTime":"2025-05-03T01:35:20.0168","operateTime":"2025-05-03T01:35:20.016801"}
 * 2025-05-03 01:36:48.447  INFO 58935 --- [demo-kafka-spring-producer] [retryTestTopicKafkaListener-dlt-1                           ] c.z.d.k.s.r.s.MyCustomDltProcessor                           : dlt message is {"id":54919281309270047,"userCode":"userCode RiVpyjee","userName":"userName fMVfGvwz","validDate":"2025-05-03","invalidDate":"2026-05-03","validFlag":"1","deleteFlag":"0","createTime":"2025-05-03T01:35:20.0168","operateTime":"2025-05-03T01:35:20.016801"}
 *
 * <p>可以看到，在将消息转发到 dlt topic 之后，会执行 dlt 消息处理器程序中的方法
 *
 * @author z2huo
 */
@RequiredArgsConstructor
@Slf4j
@Component("customDltProcessor")
public class MyCustomDltProcessor {

    public void processDltMessage(String message) {
        log.info("dlt message is {}", message);
    }

}
